/**
 * Created by Jack Xue on 20101202
 */
package org.code.jack.jweberp.domain;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class SystemDictionary implements Serializable {
	private static final long serialVersionUID = 6397066858542171792L;

	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	private Long id;

	@Column(length = 30, nullable = false, unique = true)
	private String sn;// 编号
	private String name;// 字典名称
	private String intro;// 字典简介

	@OrderBy("sequence desc")
	@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	private Set<SystemDictionaryDetail> children = new TreeSet<SystemDictionaryDetail>(new Comparator<SystemDictionaryDetail>() {
		public int compare(SystemDictionaryDetail o1, SystemDictionaryDetail o2) {
			return -(o1.getSequence() - o2.getSequence());
		}
	});

	private Date inputDate = new Date();// 添加日期
	private Integer sequence = 1;// 排序

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getSn() {
		return sn;
	}

	public void setSn(String sn) {
		this.sn = sn;
	}

	public Integer getSequence() {
		return sequence;
	}

	public void setSequence(Integer sequence) {
		this.sequence = sequence;
	}

	public String getName() {
		return name;
	}

	public Date getInputDate() {
		return inputDate;
	}

	public void setInputDate(Date inputDate) {
		this.inputDate = inputDate;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIntro() {
		return intro;
	}

	public void setIntro(String intro) {
		this.intro = intro;
	}

	public Set<SystemDictionaryDetail> getChildren() {
		return children;
	}

	public void setChildren(Set<SystemDictionaryDetail> children) {
		this.children = children;
	}

}
